package com.itnoob.whitelist.service;

import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhoujun
 * @date 2025/3/20 23:34
 */
@Service
public class WhiteListService {

    /**
     * 校验服务
     * @param userOrIp
     * @param value
     * @param global
     */
    public void check(String userOrIp , String[] value, List<String> global){

        //合并方法上的白名单和全局白名单
        List<String> list = new ArrayList<>(Arrays.asList(value));
        list.addAll(global);
        //如果用户或者ip不在白名单中,抛出异常
        if (!list.contains(userOrIp)){
            throw new RuntimeException("userOrIp is not in whiteList.");
        }


    }
}
